package com.vsu.bookstore.mvc.ui;

import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vsu.bookstore.BookstoreApplication;

@SuppressWarnings("serial")
public class NavigationButtonView extends AbstractView
{
  private final HorizontalLayout layout = new HorizontalLayout();

  private final Button checkOutButton = new Button("Checkout");

  private final Button newItemButton = new Button("New Item");

  public NavigationButtonView()
  {
    setHeight("30px");
    layout.setHeight("50px");
    layout.setWidth("100%");
    layout.setMargin(false);
    layout.setSpacing(false);
    newItemButton.setWidth("100%");
    newItemButton.setIcon(new ThemeResource("icons/new.png"));
    checkOutButton.setWidth("100%");
    checkOutButton.setIcon(new ThemeResource("icons/checkout.png"));
    checkOutButton.addListener(new Button.ClickListener()
    {
      public void buttonClick(final ClickEvent event)
      {
        ((BookstoreApplication)getApplication()).ui().checkout();
      }
    });
    newItemButton.addListener(new Button.ClickListener()
    {
      public void buttonClick(final ClickEvent event)
      {
        ((BookstoreApplication)getApplication()).ui().createNewItem();
      }
    });
    layout.addComponent(newItemButton);
    layout.addComponent(checkOutButton);
    layout.setComponentAlignment(newItemButton, Alignment.TOP_LEFT);
    layout.setComponentAlignment(checkOutButton, Alignment.TOP_RIGHT);
    setCompositionRoot(layout);
  }

  @Override
  protected void onView()
  {
  }

}

